package sto.android.app;

import java.io.File; 
import sto.android.app.StoJNI.ScanCallBack;
 
import android.content.Context;
import android.content.Intent; 
import android.net.Uri; 
import android.provider.Settings; 

public class RXC40Scanner {
	private static final String TAG = "BarcodeAPI";

	public static RXC40Scanner instance = null;

	public ScanCallBack scanCallBack;

	public static synchronized RXC40Scanner getInstance() {
		if (instance == null) {
			instance = new RXC40Scanner();
		}
		return instance;
	}

	private RXC40Scanner() {
	}

	// 
	public native void SetScannerOn();

	public native void SetScannerStart();

	public native void SetScannerRetriger();

 

	public native void SetScannerStop();

	public native void SetScannerOff();

	public native void scannerReset();

	public native String GetMachineCode();

	public native boolean GetScannerIsScanning();

	public native int SetScannerPara(int para, int value);
	public native void SetScannerTimerOut(int sec);
	public native int getmScanModel ();
	public native int getSysBuildVer();
	public native String getJniVer();
	
	 
	
 
	public native int GetScannerPara(int para);
	
 
	public native String SetScannerPara(String para, String value);
	
	 
	public native byte[] GetScannerPara(String para);
	
	public native String GetStatusUSBDebug(Context actObj);

	public native int GetStatusBarExpand();//  屏蔽状态栏下拉 ;1 使能允许，0禁止下拉

	public native int GetStatusInstallManager();

	public native int GetStatusScreenLock();

	public native int GetStatusWakeUp();// 1 电源键唤醒	0 任意键唤醒

	public native int GetTouchStatus();

	public native int GetMenuStatus();

	public native int GetBackStatus();

	public native int GetHomeKeyStatus();

	public native int GetKeydownTone();
 
	

	public boolean isGpsOpened(Context context) { 
		String str=Settings.Secure.getString(context.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
		if(str!=null){
			return str.contains("gps");
		}else{
			return false;
		}
	}

	public void SetSystemReboot(Context context) {
		Intent intent = new Intent("ACTION_USER_REBOOT");
		context.sendBroadcast(intent);
	}

	public void SetSystemShutdown(Context context) {
		Intent intent = new Intent("ACTION_USER_SHUTDOWN");
		context.sendBroadcast(intent);
	}

	public void SetSystemTime(Context context, String mm) {
//		Intent intent = new Intent("ACTION_USER_SETDATETIME");
//		intent.putExtra("USER_SETDATETIME_VALUE", mm);
//		context.sendBroadcast(intent);
		//涓哄吋瀹规棫宸存灙,鏀规垚濡備笅:
		int year,month,day,hour,min,seconds;
		 
		java.util.Date dDate=new java.util.Date(Long.valueOf(mm));
		java.util.Calendar calendar=java.util.Calendar.getInstance();
		calendar.setTime(dDate);
		year=calendar.get(java.util.Calendar.YEAR );
		month=calendar.get(java.util.Calendar.MONTH )+1;
		day=calendar.get(java.util.Calendar.DATE );
		hour=calendar.get(java.util.Calendar.HOUR_OF_DAY );
		min=calendar.get(java.util.Calendar.MINUTE );
		seconds=calendar.get(java.util.Calendar.SECOND );
		
		Intent intent = new Intent("ACTION_USER_SETDATETIME");
			intent.putExtra("USER_SETDATETIME_YEAR", year);
			intent.putExtra("USER_SETDATETIME_MONTH", month);
			intent.putExtra("USER_SETDATETIME_DAY", day);
			intent.putExtra("USER_SETDATETIME_HOUR", hour);
			intent.putExtra("USER_SETDATETIME_MINUTE",min);
			intent.putExtra("USER_SETDATETIME_SECONDS", seconds);
			context.sendBroadcast(intent);
	}

	/**
	 *  屏蔽/开启状态栏下拉 说明：false:为禁止
	 */
	public void TurnOffStatusBar(Context context, boolean isAllowExpand) {
		Intent intent = new Intent("ACTION_USER_SET_STATUSBAR");
		intent.putExtra("USER_SET_STATUSBAR_PARA", isAllowExpand);//  false涓虹姝�
		context.sendBroadcast(intent);
	}

	public void SetUSBDebug(Context context, boolean isDebug) {
		Intent intent = new Intent("ACTION_USER_USBDEBUG");
		intent.putExtra("USER_USBDEBUG", isDebug);// false绂佹USB璋冭瘯
		context.sendBroadcast(intent);
	}


	/**
	 * 物理按键音
	 * 
	 * @param isTone
	 *            true:开启;false:关闭
	 */
	public void setKeyDownTone(Context context, boolean isTone) {
		Intent intent = new Intent("ACTION_USER_KEYVOICE");
		intent.putExtra("USER_SET_KEYVOICE", isTone);
		context.sendBroadcast(intent);
	}
 

	/**
	 * 屏蔽物理按键(扫描键除外)
	 * 
	 * @param isen
	 *            true:为拦截所有按键;false为开启所有按键
	 */
	public void setInterruptKeys(Context context, boolean isen) {
		Intent intent = new Intent("ACTION_USER_INTERR_KEYS");

		intent.putExtra("USER_INTERR_KEYS", isen);
		context.sendBroadcast(intent);
	}

	
	/**
	 * 
	 * @param context
	 * @param isDisabled:true为禁止
	 */
	public void disableHomeKeys(Context context,boolean isDisabled){
		//disableKeypadEnableCustom(context,
		//		String.valueOf(android.view.KeyEvent.KEYCODE_HOME));
		
		//为兼容旧巴枪而改的
		Intent intent = new Intent("ACTION_INTERCEPT_HOME_KEYS");
		intent.putExtra("INTERCEPT_HOME_KEYS_ENABLE", isDisabled);
		context.sendBroadcast(intent);
		
	}
	/*
	 *   自定义屏蔽物理按键 参数String：要屏蔽的按键 以逗号隔开，例如屏蔽menu键和方向上键 eg：
	 * ""+android.view.KeyEvent
	 * .KEYCODE_MENU+","+android.view.KeyEvent.KEYCODE_DPAD_UP+"
	 */
	public void disableKeypadEnableCustom(Context context, String customstr) {
		Intent intent = new Intent("ACTION_USER_DEFINE_INTERR_KEYS");
		intent.putExtra("USER_DEFINE_INTERR_KEYS", customstr);
		context.sendBroadcast(intent);
	}
	public void turnOnOffGPS(Context context,boolean status){
		Intent intent = new Intent("ACTION_USER_SET_GPS");
		intent.putExtra("USER_SET_GPS", status);
		context.sendBroadcast(intent);
	}

	public void setKeyboardEn(Context context, int keyValue) {
		Intent intent = new Intent("ACTION_USER_SET_KEYSEN");
		intent.putExtra("USER_SET_KEYSEN", keyValue);
		context.sendBroadcast(intent);
	}
	/**
	 *  屏蔽 / 使能 浏览器访问
	 */
	public   void TurnOnOffBrowser(Context context,boolean set){
		Intent intent = new Intent("ACTION_USER_SET_BROWSER");
		intent.putExtra("USER_SET_BROWSER", set);
		context.sendBroadcast(intent);
	}
	
	/**
	 *  屏蔽安装APK
	 * @param context
	 * @param set
	 */
	public void InstallApkEn(Context context,boolean set){
		Intent intent = new Intent("ACTION_USER_SET_INSTALL");
		intent.putExtra("USER_SET_INSTALL", set);
		context.sendBroadcast(intent);
	}
	
	public void SetScreenLock(Context context,boolean isLock){
		Intent intent = new Intent("ACTION_USER_SET_SCREEN_LOCK");
		intent.putExtra("USER_SET_SCREEN_LOCK", isLock);
		context.sendBroadcast(intent);
	}
	/**
	 *  设置按键唤醒
	 * @param context
	 * @param isPowerKey :true:只有电源键才能唤醒;false:任意键
	 */
	public void setWakeup(Context context,boolean isPowerKey){
		Intent intent = new Intent("ACTION_USER_SET_WAKEUP");
		intent.putExtra("USER_SET_WAKEUP", isPowerKey);
		context.sendBroadcast(intent);
	}
	
	
	/**
	 * 设置 触摸屏 
	 * @param context
	 * @param isEn true:可用;false:禁用 
	 */
	public void setTouchStatusEn(Context context,boolean isEn){
		Intent intent = new Intent("ACTION_USER_SET_TP");
		intent.putExtra("USER_SET_TP", isEn);
		context.sendBroadcast(intent);
	}
	public void  installApkWithSilence(Context context,String  packagePath,boolean isRun){
		String action="";
		Intent intent = new Intent();
		if(getSysBuildVer()==1){
		  action="android.intent.action.VIEW.HIDDEN";	  
		  intent.putExtra("USER_SET_IS_SILENT", true);
		  intent.putExtra("USER_SET_AUTO_RUN", isRun);	
		}else {		 
			action= Intent.ACTION_VIEW;
		}
		 intent.setDataAndType(Uri.fromFile(new File(packagePath)),
				 "application/vnd.android.package-archive");
		intent.setAction( action);
		intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		context.startActivity(intent); 
	}

	public void setScanResults(String info) {
		if (info == null) {
			return;
		}
		if (scanCallBack != null) {
			scanCallBack.onScanResults(info);
		}

	}

	static {
		System.loadLibrary("RXC40Dev");
	}
}
